(function () {
    //定义一个数值和字符串的联合类型（10分
    let obj: (number | string)[] = ['马帅', 18]

    //定义一个类型断言（10分）
    let obj1: any = 'Hi hello'
    let str: number = (<string>obj1).length
    let str1: number = (obj1 as string).length

    //定义一个 void 实现函数的无返回值（10分）
    function fn(): void { }

    //定义一个 never 的函数（10分）
    // 返回never的函数必须存在无法达到的终点
    function error(message: string): never {
        throw new Error(message);
    }
    // 推断的返回值类型为never
    function fail() {
        return error("Something failed");
    }

    // 返回never的函数必须存在无法达到的终点
    function infiniteLoop(): never {
        while (true) {
        }
    }

    //分别定义 es5 和 ts 的函数定义（10分）

    function fn1() {
        var name = "Hello"
        return name
    }
    function fn2() {
        let name = 20
        let name1 = name + 20

        return name1
    }

    //定义函数时， 分别实现参数类型、剩余参数、默认参数（10分）

    function fn3(name: string, ...str: (string | number)[]) {
        return `${name},${str}`
    }
    console.log(fn3("马帅", '男', 19));

    //实现一个函数重载（10分）

    let suits = ["hearts", "spades", "clubs", "diamonds"];

    function pickCard(x: { suit: string; card: number; }[]): number;
    function pickCard(x: number): { suit: string; card: number; };
    function pickCard(x): any {
        // Check to see if we're working with an object/array
        // if so, they gave us the deck and we'll pick the card
        if (typeof x == "object") {
            let pickedCard = Math.floor(Math.random() * x.length);
            return pickedCard;
        }
        // Otherwise just let them pick the card
        else if (typeof x == "number") {
            let pickedSuit = Math.floor(x / 13);
            return { suit: suits[pickedSuit], card: x % 13 };
        }
    }

    let myDeck = [{ suit: "diamonds", card: 2 }, { suit: "spades", card: 10 }, { suit: "hearts", card: 4 }];
    let pickedCard1 = myDeck[pickCard(myDeck)];
    alert("card: " + pickedCard1.card + " of " + pickedCard1.suit);

    let pickedCard2 = pickCard(15);
    alert("card: " + pickedCard2.card + " of " + pickedCard2.suit);


    //使用 es5 的方式定义一个类和es6中定义类（10分）
    
    function fn4(){
       
    }
    fn4.prototype.Setpospr=()=>{
        console.log('ES5');
        
    }
  
    let str2=new fn4()
    console.log(str2.Setpospr());
    
    class name {
        Setpospr1(){
            console.log('ES6');
        }
    }
   /*  let str3=new name()
    console.log(str3.Setpospr1()); */

    //在 ts 中定义一个类并实现继承（10分）
       class names extends name{
           constructor(){
               super()
           }
       }
       let obj2=new names()
       console.log(obj2.Setpospr1);
       

})()